<xsl:stylesheet version='1.0'
  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:db="http://docbook.org/ns/docbook"
  xmlns:pbs="http://schema.pbs.gov.au"
  xmlns:int="http://schema.pbs.gov.au/DoHA-Internal"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:skos="http://www.w3.org/2004/02/skos/core#">

  <xsl:import href='common.xsl'/>

  <db:article>
    <db:info>
      <db:title>AMT2 Extract File</db:title>

      <db:copyright>
        <db:year>2013</db:year>
        <db:year>2012</db:year>
        <db:year>2011</db:year>
        <db:holder>Commonwealth of Australia</db:holder>
      </db:copyright>

      <db:legalnotice>
        <db:para>This software is copyrighted by the Commonwealth of Australia ("The Commonwealth").  The following terms apply to all files associated with the software unless explicitly disclaimed in individual files.</db:para>
        <db:para>Permission is hereby granted to use, copy, modify, distribute, and license this software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to this software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply.</db:para>
        <db:para>IN NO EVENT SHALL THE COMMONWEALTH OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</db:para>
        <db:para>THE COMMONWEALTH SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE COMMONWEALTH HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.</db:para>
      </db:legalnotice>

      <db:author>
        <db:personname>Steve Ball</db:personname>
        <db:email>Steve.Ball@health.gov.au</db:email>
        <db:affiliation>
          <db:orgname>Department of Health and Ageing</db:orgname>
          <db:orgdiv>PharmBiz</db:orgdiv>
        </db:affiliation>
      </db:author>

      <db:revhistory>
      <db:revision>
          <db:revnumber>2.2.2</db:revnumber>
          <db:date>2013-11-27</db:date>
          <db:authorinitials>JPK</db:authorinitials>
          <db:revremark>Add MOA, improve documentation.</db:revremark>
        </db:revision>
        <db:revision>
          <db:revnumber>2.2.1</db:revnumber>
          <db:date>2013-09-23</db:date>
          <db:authorinitials>SRB</db:authorinitials>
          <db:revremark>Improve documentation.</db:revremark>
        </db:revision>
        <db:revision>
          <db:revnumber>2.2</db:revnumber>
          <db:date>2013-08-28</db:date>
          <db:authorinitials>SRB</db:authorinitials>
          <db:revremark>Added mp-int, pr-int.</db:revremark>
        </db:revision>
        <db:revision>
          <db:revnumber>2.1</db:revnumber>
          <db:date>2012-11-21</db:date>
          <db:authorinitials>SRB</db:authorinitials>
          <db:revremark>Added mq-pack. Added mq-uu as a synonym for mq. Change default to display mq-pack.</db:revremark>
        </db:revision>
        <db:revision>
          <db:revnumber>2.0</db:revnumber>
          <db:date>2012-11-14</db:date>
          <db:authorinitials>SRB</db:authorinitials>
          <db:revremark>Create a branch to provide different format.</db:revremark>
        </db:revision>
        <db:revision>
          <db:revnumber>1.41</db:revnumber>
          <db:date>2012-11-07</db:date>
          <db:authorinitials>DMM</db:authorinitials>
          <db:revremark>Added documentation on the output format.</db:revremark>
        </db:revision>
        <db:revision>
          <db:revnumber>1.4</db:revnumber>
          <db:date>2012-10-31</db:date>
          <db:authorinitials>SB</db:authorinitials>
          <db:revremark>Updated to PBS XML Schema v2.8.1</db:revremark>
        </db:revision>
        <db:revision>
          <db:revnumber>1.3</db:revnumber>
          <db:date>2011-11-14</db:date>
          <db:authorinitials>DMM</db:authorinitials>
          <db:revremark>Modified keys to address performance issues</db:revremark>
        </db:revision>
        <db:revision>
          <db:revnumber>1.2</db:revnumber>
          <db:date>2011-10-19</db:date>
          <db:authorinitials>DMM</db:authorinitials>
          <db:revremark>Updated to PBS XML v2.6.</db:revremark>
        </db:revision>
        <db:revision>
          <db:revnumber>1.1</db:revnumber>
          <db:date>2011-06-02</db:date>
          <db:authorinitials>SRB</db:authorinitials>
          <db:revremark>Updated to new specification.</db:revremark>
        </db:revision>
        <db:revision>
          <db:revnumber>1.0</db:revnumber>
          <db:date>2011-05-09</db:date>
          <db:authorinitials>SRB</db:authorinitials>
          <db:revremark>Initial version.</db:revremark>
        </db:revision>
      </db:revhistory>
    </db:info>

    <db:para>This XSL stylesheet produces an extract file (<db:filename>amt yyyymmdd.txt</db:filename>) from a PBS XML document containing details of AMT identifiers for PBS items. Only ready-prepared and infusible items are included in the extract.</db:para>
    <db:para>The source document must be a PBS XML document.</db:para>
    <db:para>The result document is a text file.</db:para>
    <db:para>The default field delimiter in this file is the exclamation mark (!) (see 'delimiter' parameter, below).</db:para>
    <db:para>Column values and their order are configurable using the 'display' parameter, see below.</db:para>
    <db:para>NB. the order of the descriptions of field names below does not necessarily reflect their order in the output.</db:para>
    <db:table>
      <db:tgroup cols="4" align="left" colsep="1" rowsep="1">
        <db:colspec colnum="3" align="right"/>
        <db:thead>
          <db:row>
            <db:entry>Field Name</db:entry>
            <db:entry>Format</db:entry>
            <db:entry>Indicative Length</db:entry>
            <db:entry>Description</db:entry>
          </db:row>
        </db:thead>
        <db:tbody>
          <db:row>
            <db:entry>program-code</db:entry>
            <db:entry>Character</db:entry>
            <db:entry>2</db:entry>
            <db:entry>As per Section 10  Drug Type Codes.</db:entry>
          </db:row>
          <db:row>
            <db:entry>item-code</db:entry>
            <db:entry>Character</db:entry>
            <db:entry>6</db:entry>
            <db:entry>Alphanumeric characters in format (n)nnnna.</db:entry>
          </db:row>
          <db:row>
            <db:entry>manufacturer-code</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>Two character alphabetic, refer to file Mnfr yyyymmdd.txt. Two character alphabetic code in the Schedule Book.</db:entry>
          </db:row>
          <db:row>
            <db:entry>brand-name</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>TPP's 'Brand Name' as used in the PBS.</db:entry>
          </db:row>
          <db:row>
            <db:entry>unit-of-measure</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>E.g. Milligram, Micrograms, International Units.</db:entry>
          </db:row>
          <db:row>
            <db:entry>mp-id</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>AMT Medicinal Product SNoMED-CT Code.</db:entry>
          </db:row>
          <db:row>
            <db:entry>mp-pt</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>AMT Medicinal Product preferred term.</db:entry>
          </db:row>
          <db:row>
            <db:entry>mpp-id</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>AMT Medicinal Product Pack SNoMED-CT Code.</db:entry>
          </db:row>
          <db:row>
            <db:entry>mpp-pt</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>AMT Medicinal Product Pack preferred term.</db:entry>
          </db:row>
          <db:row>
            <db:entry>tpuu-id</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>AMT Trade Product Unit-of-use SNoMED-CT Code.</db:entry>
          </db:row>
          <db:row>
            <db:entry>tpuu-pt</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>AMT Trade Product Unit-of-use preferred term.</db:entry>
          </db:row>
          <db:row>
            <db:entry>tpp-id</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>AMT Trade Product Pack SNoMED-CT Code.</db:entry>
          </db:row>
          <db:row>
            <db:entry>tpp-pt</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>AMT Trade Product Pack preferred term.</db:entry>
          </db:row>
          <db:row>
            <db:entry>vial-content</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>The number of UOM's in the TPUU (ie. a single vial).</db:entry>
          </db:row>     
          <db:row>
            <db:entry>mq-pack</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>For ready-prepared items the maximum quantity (in terms of pack). Infusible items leave this field blank.</db:entry>
          </db:row>
          <db:row>
            <db:entry>mq-uu</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>For ready-prepared items the maximum quantity (in terms of unit-of-use). For infusible items the maximum amount of Medicinal Product in terms of UOM.</db:entry>
          </db:row>
          <db:row>
            <db:entry>cemp-tpp</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>Commonwealth's 'Ex-Manufacturer Price' for a manufacturer's pack.</db:entry>
          </db:row>
          <db:row>
            <db:entry>cemp-tpuu</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>Commonwealth's 'Ex-Manufacturer Price' for a manufacturer's unit-of-use.</db:entry>
          </db:row>
          <db:row>
            <db:entry>memp-tpp</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>Manufacturer's 'Ex-Manufacturer Price' for a manufacturer's pack.</db:entry>
          </db:row>
          <db:row>
            <db:entry>memp-tpuu</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>Manufacturer's 'Ex-Manufacturer Price' for a manufacturer's unit-of-use.</db:entry>
          </db:row>
          <db:row>
            <db:entry>pfdi</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>Value of Premium Free Dispensing Incentive.</db:entry>
          </db:row>
          <db:row>
            <db:entry>NOT INCLUDED IN DISPLAY DEFAULT</db:entry>
            <db:entry></db:entry>
            <db:entry></db:entry>
            <db:entry>-------------------------------------------</db:entry>
          </db:row>
          <db:row>
            <db:entry>moa</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>Manner of Administration</db:entry>
          </db:row>
          <db:row>
            <db:entry>mpuu-id</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>AMT Medicinal Product Unit-of-use SNoMED-CT Code.</db:entry>
          </db:row>
          <db:row>
            <db:entry>mpuu-pt</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>AMT Medicinal Product Unit-of-use preferred term.</db:entry>
          </db:row>                                        
          <db:row>
            <db:entry>pack-content</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>The number of UOM's in the TPP.</db:entry>
          </db:row>
          <db:row>
            <db:entry>mq</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>For ready-prepared items the maximum quantity (in terms of unit-of-use). For infusible items the maximum amount of Medicinal Product in terms of UOM.</db:entry>
          </db:row>                                                  
          <db:row>
            <db:entry>mp-int</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>Internal description of MP. Selects shortest description if there are multiple available.</db:entry>
          </db:row>
          <db:row>
            <db:entry>pr-int</db:entry>
            <db:entry>Character</db:entry>
            <db:entry></db:entry>
            <db:entry>Internal description of prescribing rule.</db:entry>
          </db:row>
        </db:tbody>
      </db:tgroup>
    </db:table>
  </db:article>

  <xsl:output method='text'/>

  <db:param>Fields to be included, in order. Delimited by comma.</db:param>
  <xsl:param name="display" select="'program-code,item-code,manufacturer-code,brand-name,unit-of-measure,mp-id,mp-pt,mpp-id,mpp-pt,tpuu-id,tpuu-pt,tpp-id,tpp-pt,vial-content,mq-pack,mq-uu,cemp-tpp,cemp-tpuu,memp-tpp,memp-tpuu,pfdi'"/>

  <db:param>Whether to display header.</db:param>
  <xsl:param name='include-header' select='0'/>

  <db:param>What character to use to separate the data fields.</db:param>
  <xsl:param name='delimiter' select='"!"'/>

  <db:param>What character to use to quote the data fields.</db:param>
  <xsl:param name='quote' select='""'/>
  
  <db:param>What character to use to separate the data records.</db:param>
  <xsl:param name='eom' select='"&#xa;"'/>
  
  <xsl:key name='tppID' match='/pbs:root/pbs:drugs-list/pbs:mp/pbs:mpp/pbs:tpp' use='concat("#", @xml:id)'/>

  <xsl:key name='orgID' match='/pbs:root/pbs:organisations-list/pbs:organisation' use='concat("#", @xml:id)'/>
  
  <xsl:key name='concept' match='/pbs:root/rdf:RDF/skos:Concept' use='@rdf:about'/>
 
  <db:template name='root'>
    <db:refpurpose>Check Document Version</db:refpurpose>
    <db:para>Make sure that the source document uses the correct version of the PBS XML Schema.</db:para>
  </db:template>
  <xsl:template match='/'>
    <xsl:variable name='major' select='substring-before(/*/@version, ".")'/>

    <xsl:choose>
      <xsl:when test='$major >= 2'>
        <xsl:if test='$include-header = 1'>
          <xsl:value-of select="translate($display, ',', $delimiter)"/>
          <xsl:value-of select="$eom"/>
        </xsl:if>
        <xsl:apply-templates
          select='/pbs:root/pbs:schedule/pbs:listings-list/pbs:prescribing-rule[not(self::pbs:solvent-rule|self::pbs:extemporaneous-preparation|self::pbs:standard-formula-preparation|self::pbs:drug-tariff)]'/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message terminate='yes'>This stylesheet is designed to operate upon a Schedule XML document that conforms to version 2.5 (or later) of the PBS XML Schema.  See http://xml.pbs.gov.au/ for more information on the PBS XML Schema, and for a version of this XSL stylesheet that operates on documents that conform to an earlier version of the schema.</xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match='pbs:prescribing-rule'>
    <xsl:choose>
      <xsl:when test='pbs:infusible'>
        <xsl:apply-templates select='*/pbs:pricing/pbs:reimbursement/pbs:prices/pbs:tpp-list/pbs:tpp-reference'>
          <xsl:with-param name='pr' select='.'/>
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select='*/pbs:pricing/pbs:prices/pbs:tpp-reference'>
          <xsl:with-param name='pr' select='.'/>
        </xsl:apply-templates>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match='pbs:tpp-reference'>
    <xsl:param name='pr' select='/..'/>

    <xsl:call-template name="display">
      <xsl:with-param name="what" select="$display"/>
      <xsl:with-param name="pr" select="$pr"/>
      <xsl:with-param name="tpp-ref" select="."/>
      <xsl:with-param name="tpp" select="key('tppID', @xlink:href)"/>
      <xsl:with-param name="org" select="key('orgID', key('tppID', @xlink:href)/pbs:organisation-reference/@xlink:href)"/>
    </xsl:call-template>
    <xsl:value-of select="$eom"/>
  </xsl:template>

  <xsl:template name="display">
    <xsl:param name="what"/>
    <xsl:param name="pr" select="/.."/>
    <xsl:param name="tpp-ref" select="/.."/>
    <xsl:param name="tpp" select="/.."/>
    <xsl:param name="org" select="/.."/>
    
    <xsl:choose>
      <xsl:when test="not($what)"/>
      <xsl:when test="contains($what, ',')">
        <xsl:call-template name="display">
          <xsl:with-param name="what" select="normalize-space(substring-before($what, ','))"/>
          <xsl:with-param name="pr" select="$pr"/>
          <xsl:with-param name="tpp-ref" select="$tpp-ref"/>
          <xsl:with-param name="tpp" select="$tpp"/>
          <xsl:with-param name="org" select="$org"/>
        </xsl:call-template>
        <xsl:call-template name="display">
          <xsl:with-param name="what" select="normalize-space(substring-after($what, ','))"/>
          <xsl:with-param name="pr" select="$pr"/>
          <xsl:with-param name="tpp-ref" select="$tpp-ref"/>
          <xsl:with-param name="tpp" select="$tpp"/>
          <xsl:with-param name="org" select="$org"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$what = 'program-code'">
        <xsl:apply-templates select='$pr/ancestor::pbs:listings-list/pbs:info/pbs:code' mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'item-code'">
        <xsl:apply-templates select='$pr/pbs:code' mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'manufacturer-code'">
        <xsl:apply-templates select='$org/pbs:code' mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'unit-of-measure' and
        $pr/*/pbs:maximum-quantity/@reference = 'unit-of-measure'">
        <xsl:value-of select='$quote'/>
        <xsl:apply-templates select='$pr/*/pbs:maximum-quantity/@amount' mode='textonly'/>
        <xsl:text> </xsl:text>
        <xsl:apply-templates select='$pr/*/pbs:maximum-quantity/@unit' mode='textonly'/>
        <xsl:value-of select='$quote'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'unit-of-measure'">
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'brand-name'">
        <xsl:value-of select='$quote'/>
        <xsl:apply-templates select='$tpp/db:subtitle' mode='textonly'/>
        <xsl:value-of select='$quote'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'mp-id'">
        <xsl:apply-templates select='$tpp/../../pbs:code[@scheme = "urn:snomed-org/sct"]'
          mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'mp-pt'">
        <xsl:value-of select='$quote'/>
        <xsl:apply-templates select='$tpp/../../db:title' mode='textonly'/>
        <xsl:value-of select='$quote'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'mp-int'">
        <xsl:value-of select='$quote'/>
        <xsl:for-each select="$tpp/../../int:label[@role]">
          <xsl:sort select="string-length()" order="ascending"/>
          <xsl:if test="position() = 1">
            <xsl:apply-templates mode='textonly'/>
          </xsl:if>
        </xsl:for-each>
        <xsl:value-of select='$quote'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'pr-int'">
        <xsl:value-of select='$quote'/>
        <xsl:apply-templates select='$pr/int:title[@role]' mode='textonly'/>
        <xsl:value-of select='$quote'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'mpuu-id'">
        <xsl:apply-templates select='$tpp/../pbs:mpuu/pbs:code[@scheme = "urn:snomed-org/sct"]'
          mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'mpuu-pt'">
        <xsl:value-of select='$quote'/>
        <xsl:apply-templates select='$tpp/../pbs:mpuu/db:title' mode='textonly'/>
        <xsl:value-of select='$quote'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'mpp-id'">
        <xsl:apply-templates select='$tpp/../pbs:code[@scheme = "urn:snomed-org/sct"]'
          mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'mpp-pt'">
        <xsl:value-of select='$quote'/>
        <xsl:apply-templates select='$tpp/../db:title' mode='textonly'/>
        <xsl:value-of select='$quote'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'tpuu-id'">
        <xsl:apply-templates select='$tpp/pbs:tpuu/pbs:code[@scheme = "urn:snomed-org/sct"]'
          mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'tpuu-pt'">
        <xsl:value-of select='$quote'/>
        <xsl:apply-templates select='$tpp/pbs:tpuu/db:title' mode='textonly'/>
        <xsl:value-of select='$quote'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'tpp-id'">
        <xsl:apply-templates select='$tpp/pbs:code[@scheme = "urn:snomed-org/sct"]'
          mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'tpp-pt'">
        <xsl:value-of select='$quote'/>
        <xsl:apply-templates select='$tpp/db:title' mode='textonly'/>
        <xsl:value-of select='$quote'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'pack-content'">
        <xsl:apply-templates select='$tpp/pbs:pack-content' mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'vial-content'">
        <xsl:apply-templates select='$tpp/pbs:tpuu/pbs:vial-content' mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="($what = 'mq' or $what = 'mq-uu') and
        $pr/*/pbs:maximum-quantity[@reference = 'unit-of-measure']">
        <xsl:apply-templates select='$pr/*/pbs:maximum-quantity[@reference = "unit-of-measure"]' mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="($what = 'mq' or $what = 'mq-uu') and
        $pr/*/pbs:maximum-quantity[@reference = 'unit-of-use']">
        <xsl:apply-templates select='$pr/*/pbs:maximum-quantity[@reference = "unit-of-use"]' mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'mq-pack' and
        $pr/*/pbs:maximum-quantity[@reference = 'unit-of-measure']">
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'mq-pack' and
        $pr/*/pbs:maximum-quantity[@reference = 'pack']">
        <xsl:apply-templates select='$pr/*/pbs:maximum-quantity[@reference = "pack"]' mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="($what = 'mq' or $what = 'mq-uu' or $what = 'mq-pack')">
        <xsl:apply-templates select='$pr/*/pbs:maximum-quantity[1]' mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'cemp-tpuu'">
        <xsl:apply-templates
          select='$pr/pbs:infusible/pbs:pricing/pbs:reimbursement/pbs:prices/pbs:tpp-list[pbs:tpp-reference[@xlink:href = $tpp-ref/@xlink:href]]/pbs:tpuu-ex-manufacturer'
          mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'cemp-tpp' and
        starts-with($pr/ancestor::pbs:listings-list/pbs:info/pbs:pricing-model, 'http://schema.pbs.gov.au/Pricing/ready-prepared-no-premium')">
        <xsl:apply-templates
          select='$tpp/pbs:ex-manufacturer'
          mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'cemp-tpp'">
        <xsl:apply-templates
          select='$pr/*/pbs:pricing/pbs:reimbursement/pbs:ex-manufacturer'
          mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'memp-tpuu'">
        <xsl:apply-templates
          select='$tpp/pbs:tpuu/pbs:ex-manufacturer'
          mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'memp-tpp'">
        <xsl:apply-templates
          select='$tpp/pbs:ex-manufacturer'
          mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'pfdi' and
        $pr/pbs:infusible">
        <xsl:apply-templates
          select='$pr/*/pbs:pricing/pbs:manufacturer/pbs:prices[pbs:tpp-list/pbs:tpp-reference[@xlink:href = $tpp-ref/@xlink:href]]/pbs:incentives-list/pbs:incentive[pbs:type = "http://schema.pbs.gov.au/Incentive#dispensing" or pbs:type = "incentive:dispensing"]/pbs:amount[1]'
          mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'pfdi'">
        <xsl:apply-templates
          select='$pr/*/pbs:pricing/pbs:prices[pbs:tpp-reference[@xlink:href = $tpp-ref/@xlink:href]]/pbs:incentives-list/pbs:incentive[pbs:type = "http://schema.pbs.gov.au/Incentive#dispensing" or pbs:type = "incentive:dispensing"]/pbs:amount[1]'
          mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
      <xsl:when test="$what = 'moa'">
        <xsl:apply-templates select="key('concept',$pr/*/pbs:administration/pbs:moa-value)/skos:definition" mode='textonly'/>
        <xsl:value-of select='$delimiter'/>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>
